<?php

require_once BaseUtil::getModulePath("base") . '/models/BaseDao.php';

class ConfigDao extends BaseDao {
	
	protected $_name;
	
	public function _setup() {
		$this->_name = $this->prefix() . "configs";
		parent::_setup();
	}
	
	public function updateConfig($data, $key) {
		$where =$this->db_w->quoteInto('conf_key =?',$key);
		$this->updateData($data,$where);
	}
	
	public function deleteConfig($id) {
		$isDel = array("is_delete"=>1);
		$where = $this->db_w->quoteInto('id =?',$id);
		$this->updateData($isDel,$where);
	}
	
	public function getConfig() {
		$select = $this->db_r->select();
        $select->from($this->_name,"*");
        $select->where("is_delete = 0");
        $sql = $select->__toString();
        $result = $this->db_r->fetchAll($sql);
        return $result;
	}
	
	public function getConfigByKey($key) {
		$select = $this->db_r->select();
		$select->from($this->_name,"conf_value");
		$select->where("conf_key=?",$key);
		$select->where("is_delete = 0");
		$sql = $select->__toString();
		$value= $this->db_r->fetchRow($sql);			
		return $value;
	}	
}